package 品牌管理;

import java.sql.*;
import java.util.ArrayList;

public class 查询全部品牌 {
    public static void main(String[] args) {

         ArrayList<Brand> brandList = new  ArrayList<>();

        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");

            String url = "jdbc:mysql://localhost:3306/db_jdbc_demo?characterEncoding=utf8&useSSL=false&serverTimezone=UTC";
            String user = "root";
            String pass="1234";
            conn = DriverManager.getConnection(url, user, pass);

            String sql = "SELECT * FROM t_brand";

            stmt = conn.createStatement();
            rs = stmt.executeQuery(sql);

            while (rs.next()){

                int id = rs.getInt("id");

                String brandName = rs.getString("brand_name");
                String companyName = rs.getString("company_name");
                int ordered = rs.getInt("ordered");
                String description = rs.getString("description");
                int status = rs.getInt("status");
//                System.out.println(id+brandName+companyName+ordered+description+status);
                 Brand b=new Brand(id,brandName,companyName,ordered,description,status);
                 brandList.add(b);
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                rs.close();
                stmt.close();
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        for (Brand brand : brandList) {
            System.out.println(brand);
        }

    }
}
